package admin.controllers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import admin.data.CoordinaData;
import admin.data.RouteData;
import admin.data.StoreData;
import admin.data.StoreItemData;

import models.CoordinaModel;
import models.RouteModel;
import models.StoreItemModel;
import models.StoreModel;


public class ListCoordinaServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
		response.setCharacterEncoding("UTF-8");
		
		RouteData routeData = new RouteData();
		List<RouteModel> listRoute = routeData.getListRoute();

		ArrayList<CoordinaModel> listCoordina = new ArrayList<CoordinaModel>();
		CoordinaData coordinaData = new CoordinaData();
		listCoordina = coordinaData.getCoordina("","0","","","","");	
		request.setAttribute("listCoordina", listCoordina);

		TreeMap<String, RouteModel> mapRoute = routeData.getMapRoute();
		request.setAttribute("listRoute", listRoute);
		request.setAttribute("mapRoute", mapRoute);		
		try {
			request.getRequestDispatcher("/admin/pages/list_coordina.jsp").forward(request, response);
		} catch (ServletException e) {
			//e.printStackTrace();
		}
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		
		String routeId = (String) request.getParameter("routeId");
		String status = (String) request.getParameter("status");
		String startTime = (String) request.getParameter("startTime");
		String endTime = (String) request.getParameter("endTime");
		String staffId = (String) request.getParameter("staffId");
		String coordinaId = (String) request.getParameter("coordinaId");

		ArrayList<CoordinaModel> listCoordina = new ArrayList<CoordinaModel>();		
		CoordinaData coordinaData = new CoordinaData();
		listCoordina = coordinaData.getCoordina(routeId,status,startTime,endTime,staffId,coordinaId);		
		
		RouteData routeData = new RouteData();
		List<RouteModel> listRoute = routeData.getListRoute();
		TreeMap<String, RouteModel> mapRoute = routeData.getMapRoute();
		request.setAttribute("listRoute", listRoute);
		request.setAttribute("mapRoute", mapRoute);
		request.setAttribute("listCoordina", listCoordina);
		try {
			request.getRequestDispatcher("/admin/pages/list_coordina.jsp").forward(request, response);
		} catch (ServletException e) {
			//e.printStackTrace();
		}
	}
}